﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using CalculateModelClasses;
using FileOutPut;

namespace FileOutput
{
    public class P2mFileOutput
    {
        protected static StringBuilder sb = new StringBuilder();

        /// <summary>
        /// 总的函数调用接口
        /// </summary>
        /// <param name="Paths">所有接收机的所有路径</param>
        /// <param name="Rxname">接收机名字</param>
        /// <param name="groupnum">接收机的类型号</param>
        /// <param name="filePath">存放路径</param>
        /// <param name="ProjName">工程名</param>
        public static void p2mfileoutput(List<List<CalculateModelClasses.Path>> Paths, string filePath, string ProjName)
        {
            lock (typeof(P2mFileOutput))
            {
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                if (Paths.Count != 0)
                {
                    string Rxname = Paths[0][0].node[Paths[0][0].node.Count - 1].name;
                    int Rxnum = Paths[0][0].node[Paths[0][0].node.Count - 1].num;
                    OutputDelegate output = PowerOutput.OutPath;
                    output += PathOutput.OutPath;
                    output += PlOutput.OutPath;
                    output += PgOutput.OutPath;
                    output += PgOutput.OutPath;
                    output += SpreadOutput.OutPath;
                    output += ErmOutput.OutPath;
                    output += ExmagOutput.OutPath;
                    output += ExphsOutput.OutPath;
                    output += EymagOutput.OutPath;
                    output += EyphsOutput.OutPath;
                    output += EzmagOutput.OutPath;
                    output += EzphsOutput.OutPath;
                    output(Paths, filePath, ProjName);
                    //PowerOutput.OutPath(Paths, filePath, ProjName);
                    //PathOutput.OutPath(Paths, filePath, ProjName);
                    //PlOutput.OutPath(Paths, filePath,ProjName);
                    //PgOutput.OutPath(Paths, filePath, ProjName);
                    //SpreadOutput.OutPath(Paths, filePath, ProjName);
                    //ErmOutput.OutPath(Paths, filePath, ProjName);
                    //ExmagOutput.OutPath(Paths, filePath, ProjName);
                    //ExphsOutput.OutPath(Paths, filePath, ProjName);
                    //EymagOutput.OutPath(Paths, filePath, ProjName);
                    //EyphsOutput.OutPath(Paths, filePath, ProjName);
                    //EzmagOutput.OutPath(Paths, filePath, ProjName);
                    //EzphsOutput.OutPath(Paths, filePath, ProjName);
                }
                else
                {
                    OutputDelegate1 output1 = PowerOutput.OutPath1;
                    output1 += PathOutput.OutPath1;
                    output1 += PlOutput.OutPath1;
                    output1 += PgOutput.OutPath1;
                    output1 += PgOutput.OutPath1;
                    output1 += SpreadOutput.OutPath1;
                    output1 += ErmOutput.OutPath1;
                    output1 += ExmagOutput.OutPath1;
                    output1 += ExphsOutput.OutPath1;
                    output1 += EymagOutput.OutPath1;
                    output1 += EyphsOutput.OutPath1;
                    output1 += EzmagOutput.OutPath1;
                    output1 += EzphsOutput.OutPath1;
                    output1(Paths, filePath);
                    //PowerOutput.OutPath1(Paths, filePath);
                    //PathOutput.OutPath1(Paths, filePath);
                    //PlOutput.OutPath1(Paths, filePath);
                    //PgOutput.OutPath1(Paths, filePath);
                    //SpreadOutput.OutPath1(Paths, filePath);
                    //ErmOutput.OutPath1(Paths, filePath);
                    //ExmagOutput.OutPath1(Paths, filePath);
                    //ExphsOutput.OutPath1(Paths, filePath);
                    //EymagOutput.OutPath1(Paths, filePath);
                    //EyphsOutput.OutPath1(Paths, filePath);
                    //EzmagOutput.OutPath1(Paths, filePath);
                    //EzphsOutput.OutPath1(Paths, filePath);
                }
            }
        }


        protected static Plural GetTolPower(List<CalculateModelClasses.Path> RxPaths)
        {
            Plural tolPower = new Plural();
            foreach (CalculateModelClasses.Path path in RxPaths)
            {
                tolPower += path.node[path.node.Count - 1].power;
            }
            return tolPower;

        }
        protected static double GetTolTime(List<CalculateModelClasses.Path> RxPaths)
        {
            double tolTime = 0;
            foreach (CalculateModelClasses.Path path in RxPaths)
            {
                tolTime += path.Delay;
            }
            return tolTime;
        }
        protected static double GetTolDelay(List<CalculateModelClasses.Path> RxPaths)
        {
            double tolDelay = 0;
            foreach (CalculateModelClasses.Path path in RxPaths)
            {
                tolDelay += path.Delay;
            }
            return tolDelay;
        }
        private delegate void OutputDelegate(List<List<CalculateModelClasses.Path>> Paths, string sPath, string projectName);
        private delegate void OutputDelegate1(List<List<CalculateModelClasses.Path>> Paths, string sPath);
    }
}
